﻿// JavaScript Document
var oAjax=null;
var oAction=0;
function createAjax(URL, val) {
    bzAJNoCache = new Date();
    URL += '&bzAJNoCache=' + bzAJNoCache.getTime();	
	preloadAjax(val);
	if (window.XMLHttpRequest) 
	{
		oAjax = new XMLHttpRequest();
		oAjax.onreadystatechange = process;
		oAjax.open("GET",URL, true);
		oAjax.send(null);			
	} else if (window.ActiveXObject) 
	{
		oAjax = new ActiveXObject("Microsoft.XMLHTTP");
		if (oAjax) 
		{
			oAjax.onreadystatechange = process;
			oAjax.open("GET", URL, true);
			oAjax.send();			
		}
	}
}
function  createAjaxURL(URL,val){	
	bzAJNoCache=new Date();
	URL+='-'+bzAJNoCache.getTime()+'.aspx';
	preloadAjax(val);
	if (window.XMLHttpRequest) 
	{
		oAjax = new XMLHttpRequest();
		oAjax.onreadystatechange = process;
		oAjax.open("GET", URL, true);
		oAjax.send(null);			
	} else if (window.ActiveXObject) 
	{
		oAjax = new ActiveXObject("Microsoft.XMLHTTP");
		if (oAjax) 
		{
			oAjax.onreadystatechange = process;
			oAjax.open("GET", URL, true);
			oAjax.send();			
		}
	}
}
function preloadAjax(val)
{	
	oAction=val;
	str = '<img src="/Images/ajax-loader.gif" align="center" valign="middle" border="0"/>&nbsp;Loading...';
	switch (oAction)
	{
		case 1:document.getElementById('storeBody').innerHTML=str; break;	
		case 2:document.getElementById('WriterOther').innerHTML=str; break;	
		case 3:document.getElementById('imgCaptcha').innerHTML=str; break;
		case 4:check_email_bool=1;break;
		case 5:document.getElementById('divPaymentInfo').innerHTML=str;break;
		case 6:document.getElementById('GeomancyOther').innerHTML=str;break;
		case 7:document.getElementById('divSelCate').innerHTML=str;break;
		case 8: document.getElementById('divQuickSearch').innerHTML = str; break;
		case 9: document.getElementById('nsx').innerHTML = str; break;
		case 11: break;
		case 50: break;
		case 51: break;
		case 52: break;
		case 97: document.getElementById('intro').innerHTML = str; break;
		case 98: document.getElementById('bzEWeather').innerHTML = str; break;
		case 99: document.getElementById('div_obj_flash').innerHTML = str; break;
		case 100: document.getElementById('newsother').innerHTML = str; break;
		case 1000: break;
		default: document.getElementById('otherNews').innerHTML = str; break; 				
	}
}
function process()
{
	if (oAjax.readyState == 4) 
	{		
		if (oAjax.status == 200) 
		{	
			switch (oAction)
			{
				case 1:document.getElementById('storeBody').innerHTML=oAjax.responseText;initLightbox(); break;
			    case 2:document.getElementById('WriterOther').innerHTML=oAjax.responseText; break;	
				case 3:document.getElementById('imgCaptcha').innerHTML=oAjax.responseText; break;
				case 4:check_email_exist=oAjax.responseText;check_email_bool=0;break;
				case 5:document.getElementById('divPaymentInfo').innerHTML=oAjax.responseText; break;
				case 6:document.getElementById('GeomancyOther').innerHTML=oAjax.responseText; break;
				case 7:document.getElementById('divSelCate').innerHTML=oAjax.responseText; break;
				case 8: document.getElementById('divQuickSearch').innerHTML = oAjax.responseText; break;
				case 9: document.getElementById('nsx').innerHTML = oAjax.responseText; break;
				case 11: alert(oAjax.responseText); break;

				case 50: document.getElementById('pop_div_loading').style.display = 'none'; document.getElementById('pop_div_content').innerHTML = oAjax.responseText; break;
				case 51: s = oAjax.responseText;
				    if (s == '1') {
				        alert('Website đang cập nhật');
				    } else if (s == '3') {
				        alert('Không bình chọn được. Vui lòng thử lại sau!!!');
				    } else if (s == '4') {
				        alert('Bạn không thể bình chọn 2 lần trên cùng 1 máy tính. Vui lòng chờ trong vài phút!!!');
				    } else {
				        alert('Cảm ơn bạn đã bình chọn cho sản phẩm của website. Đây là kết quả bình chọn:');
				        loadSurvey();
				    } break;
				case 52: document.getElementById('pop_div_loading_email').style.display = 'none'; document.getElementById('pop_div_content_email').innerHTML = oAjax.responseText; break;
				case 97: document.getElementById('intro').innerHTML = oAjax.responseText; break;
				case 98: document.getElementById('bzEWeather').innerHTML = oAjax.responseText; break;
				case 99: document.getElementById('div_obj_flash').innerHTML = oAjax.responseText; break;
				case 100: document.getElementById('otherNews').innerHTML = oAjax.responseText; break;
				case 1000: window.location.reload(); break;
				default: document.getElementById('otherNews').innerHTML = oAjax.responseText; break;				
			}
		}
	}
}